package edu.hcmus.sow.domain;

import java.io.Serializable;
import java.util.Calendar;
import java.util.Set;

import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinColumns;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.codehaus.jackson.annotate.JsonIgnore;

/**
 */

@Entity
@NamedQueries({
		@NamedQuery(name = "findAllFolders", query = "select myFolder from Folder myFolder"),
		@NamedQuery(name = "findFolderByCreatedDate", query = "select myFolder from Folder myFolder where myFolder.createdDate = ?1"),
		@NamedQuery(name = "findFolderById", query = "select myFolder from Folder myFolder where myFolder.id = ?1"),
		@NamedQuery(name = "findFolderByName", query = "select myFolder from Folder myFolder where myFolder.name = ?1"),
		@NamedQuery(name = "findFolderByNameContaining", query = "select myFolder from Folder myFolder where myFolder.name like ?1"),
		@NamedQuery(name = "findFolderByPrimaryKey", query = "select myFolder from Folder myFolder where myFolder.id = ?1"),
		@NamedQuery(name = "findFolderByStatus", query = "select myFolder from Folder myFolder where myFolder.status = ?1"),
		@NamedQuery(name = "findFolderByStatusContaining", query = "select myFolder from Folder myFolder where myFolder.status like ?1"),
		@NamedQuery(name = "findFolderByUpdatedDate", query = "select myFolder from Folder myFolder where myFolder.updatedDate = ?1") })
@Table(catalog = "sow", name = "folder")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain", name = "Folder")
@XmlRootElement(namespace = "SharedOnlineWorkspace/edu/hcmus/sow/domain")
public class Folder implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 */

	@Column(name = "ID", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	@XmlElement
	Integer id;
	/**
	 */

	@Column(name = "NAME", length = 50, nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String name;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "CREATED_DATE", nullable = false)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar createdDate;
	/**
	 */
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "UPDATED_DATE")
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	Calendar updatedDate;
	/**
	 */

	@Column(name = "STATUS", length = 3)
	@Basic(fetch = FetchType.EAGER)
	@XmlElement
	String status;

	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "CREATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByCreatedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "UPDATED_BY", referencedColumnName = "ID") })
	@XmlTransient
	User userByUpdatedBy;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "REPOSITORY_ID", referencedColumnName = "ID", nullable = false) })
	@XmlTransient
	Repository repository;
	/**
	 */
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumns({ @JoinColumn(name = "PARENT_ID", referencedColumnName = "ID") })
	@XmlTransient
	Folder folder;
	/**
	 */
	@OneToMany(mappedBy = "folder", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.Folder> folders;
	/**
	 */
	@OneToMany(mappedBy = "folder", cascade = { CascadeType.REMOVE }, fetch = FetchType.LAZY)
	@XmlElement(name = "", namespace = "")
	java.util.Set<edu.hcmus.sow.domain.File> files;

	/**
	 */
	public void setId(Integer id) {
		this.id = id;
	}

	/**
	 */
	public Integer getId() {
		return this.id;
	}

	/**
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 */
	public String getName() {
		return this.name;
	}

	/**
	 */
	public void setCreatedDate(Calendar createdDate) {
		this.createdDate = createdDate;
	}

	/**
	 */
	public Calendar getCreatedDate() {
		return this.createdDate;
	}

	/**
	 */
	public void setUpdatedDate(Calendar updatedDate) {
		this.updatedDate = updatedDate;
	}

	/**
	 */
	public Calendar getUpdatedDate() {
		return this.updatedDate;
	}

	/**
	 */
	public void setStatus(String status) {
		this.status = status;
	}

	/**
	 */
	public String getStatus() {
		return this.status;
	}

	/**
	 */
	public void setUserByCreatedBy(User userByCreatedBy) {
		this.userByCreatedBy = userByCreatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByCreatedBy() {
		return userByCreatedBy;
	}

	/**
	 */
	public void setUserByUpdatedBy(User userByUpdatedBy) {
		this.userByUpdatedBy = userByUpdatedBy;
	}

	/**
	 */
	@JsonIgnore
	public User getUserByUpdatedBy() {
		return userByUpdatedBy;
	}

	/**
	 */
	public void setRepository(Repository repository) {
		this.repository = repository;
	}

	/**
	 */
	@JsonIgnore
	public Repository getRepository() {
		return repository;
	}

	/**
	 */
	public void setFolder(Folder folder) {
		this.folder = folder;
	}

	/**
	 */
	@JsonIgnore
	public Folder getFolder() {
		return folder;
	}

	/**
	 */
	public void setFolders(Set<Folder> folders) {
		this.folders = folders;
	}

	/**
	 */
	@JsonIgnore
	public Set<Folder> getFolders() {
		if (folders == null) {
			folders = new java.util.LinkedHashSet<edu.hcmus.sow.domain.Folder>();
		}
		return folders;
	}

	/**
	 */
	public void setFiles(Set<File> files) {
		this.files = files;
	}

	/**
	 */
	@JsonIgnore
	public Set<File> getFiles() {
		if (files == null) {
			files = new java.util.LinkedHashSet<edu.hcmus.sow.domain.File>();
		}
		return files;
	}

	/**
	 */
	public Folder() {
	}

	/**
	 * Copies the contents of the specified bean into this bean.
	 *
	 */
	public void copy(Folder that) {
		setId(that.getId());
		setName(that.getName());
		setCreatedDate(that.getCreatedDate());
		setUpdatedDate(that.getUpdatedDate());
		setStatus(that.getStatus());
		setUserByCreatedBy(that.getUserByCreatedBy());
		setUserByUpdatedBy(that.getUserByUpdatedBy());
		setRepository(that.getRepository());
		setFolder(that.getFolder());
		setFolders(new java.util.LinkedHashSet<edu.hcmus.sow.domain.Folder>(that.getFolders()));
		setFiles(new java.util.LinkedHashSet<edu.hcmus.sow.domain.File>(that.getFiles()));
	}

	/**
	 * Returns a textual representation of a bean.
	 *
	 */
	public String toString() {

		StringBuilder buffer = new StringBuilder();

		buffer.append("id=[").append(id).append("] ");
		buffer.append("name=[").append(name).append("] ");
		buffer.append("createdDate=[").append(createdDate).append("] ");
		buffer.append("updatedDate=[").append(updatedDate).append("] ");
		buffer.append("status=[").append(status).append("] ");

		return buffer.toString();
	}

	/**
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = (int) (prime * result + ((id == null) ? 0 : id.hashCode()));
		return result;
	}

	/**
	 */
	public boolean equals(Object obj) {
		if (obj == this)
			return true;
		if (!(obj instanceof Folder))
			return false;
		Folder equalCheck = (Folder) obj;
		if ((id == null && equalCheck.id != null) || (id != null && equalCheck.id == null))
			return false;
		if (id != null && !id.equals(equalCheck.id))
			return false;
		return true;
	}
}
